package com.yanqu.road.server.logic.activity.condition;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;
import java.util.Date;

/**
 * @author ：zfr
 * @date ：2021/10/29 0:29
 */
public class ExpressionActivityChooseCondition extends BaseActivityCondition {

    public ExpressionActivityChooseCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ExpressionActivityChoose.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ExpressionActivityChoose.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(BigInteger.ZERO) > 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        String paramStr = (String) object;
        String[] split = paramStr.split(";");
        int days = DateHelper.calc2DateTDOADays(new Date(activityInfo.getBeginTime() * 1000), new Date());
        if (Integer.parseInt(split[0]) == activityInfo.getActivityId() && days == activityConditionInfo.getParamList().get(0).intValue()) {
            setValue(BigInteger.valueOf(Integer.parseInt(split[1])));
        }
    }
}
